﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;

namespace SCCN.Utility
{
    public class HttpHelper
    {
        public enum MethodType
        {
            GET,
            POST
        }
        #region Url操作

        #endregion

        /// <summary>
        /// 根据指定的传参方式获取页面参数
        /// </summary>
        /// <param name="parameters">参数名</param>
        /// <param name="type">参数类型</param>
        /// <returns>参数值</returns>
        public static string GetParameters(string parameter, MethodType type)
        {
            switch (type)
            {
                case MethodType.POST:
                    if (System.Web.HttpContext.Current.Request.Form[parameter] != null)
                        return System.Web.HttpContext.Current.Request.Form[parameter].ToString();
                    break;
                case MethodType.GET:
                    if (System.Web.HttpContext.Current.Request.QueryString[parameter] != null)
                        return System.Web.HttpContext.Current.Request.QueryString[parameter].ToString();
                    break;
            }
            return string.Empty;
        }

        /// <summary>
        /// 获取Web站点所在的实际物理路径
        /// </summary>
        /// <returns></returns>
        public static string GetWebPhysicalPath()
        {
            return System.Web.HttpContext.Current.Server.MapPath("/").ToString();
        }


        /// <summary>
        /// 弹出警告
        /// </summary>
        public static void Alert(string message, Page pg)
        {
            pg.ClientScript.RegisterClientScriptBlock(pg.GetType(), "alert",
                "<script language=javascript>alert('" + message + "');</script>");
        }


    }
}
